package org.example.springaop.proxy;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/8/1
 * Time: 22:08
 */
@Slf4j
public class JDKInvocationHandler implements InvocationHandler {

    private final Object realHouse;
    public JDKInvocationHandler(Object realHouse) {
        this.realHouse = realHouse;
    }

    @Override
    //Object proxy:生成的代理对象实例,Method method:被调用的目标方法对象,Object[] args:调用目标方法时传入的参数数组
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        log.info("JDK开始代理");
        //调用realHouse的方法
        Object invoke = method.invoke(realHouse, args);
        log.info("JDK结束代理,invoke:{}", invoke);
        return invoke;
    }
}
